package com.ibm.cps.processors.deletion;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;

/**
 * get all processors affected by the deleted processor
 * the deleted processor is the root of tree, all nodes in this tree will be searched by the order of bfs  
 * @author Jingjing Wang
 * 2015-4-29
 */
public class BFSSearch {

	public static List<String> getBFSSuccessors(String currentid,
			HashMap<String, Set<String>> parent2Successors) {
		if (currentid == null) {
			return new ArrayList<String>();
		}
		List<String> allNodes = new LinkedList<String>();
		Queue<String> restNodes = new LinkedList<String>();
		allNodes.add(currentid);
		restNodes.add(currentid);
		String currentNode;
		while (!restNodes.isEmpty()) {
			currentNode = restNodes.poll();
			Set<String> result = parent2Successors.get(currentNode);
			if (result != null) {
				allNodes.addAll(result);
				restNodes.addAll(result);
			}
		}
		return allNodes;
	}

}
